package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentsService;
import com.tanhua.server.service.MovementsService;
import com.tanhua.server.service.SmallVideosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @auther : 白月尘
 * @date : 14:29  2021/10/25
 */
@RestController
@RequestMapping("/smallVideos")
public class SmallVideosController {

    @Autowired
    private SmallVideosService smallVideosService;
    @Autowired
    private CommentsService commentsService;
    @Autowired
    private CommentController commentController;
    @Autowired
    private MovementsService movementsService;

    //上传视频
    @PostMapping
    public ResponseEntity saveVideo(MultipartFile videoThumbnail, MultipartFile videoFile) {
        smallVideosService.saveVideo(videoThumbnail, videoFile);
        return ResponseEntity.ok(null);
    }

    //小视频列表
    @GetMapping
    public ResponseEntity findVideos(@RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pageResult = smallVideosService.findVideos(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    //视频用户关注
    @PostMapping("/{uid}/userFocus")
    public ResponseEntity userFocus(@PathVariable("uid") long uid) {
        smallVideosService.saveFocusUser(uid);
        return ResponseEntity.ok(null);
    }

    //视频用户取消关注
    @PostMapping("/{uid}/userUnFocus")
    public ResponseEntity userUnFocus(@PathVariable("uid") long uid) {
        smallVideosService.deleteFocusUser(uid);
        return ResponseEntity.ok(null);
    }

    //视频点赞
    @PostMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String id) {
        smallVideosService.like(id);
        return ResponseEntity.ok(null);
    }

    @PostMapping("/{id}/dislike")
    public ResponseEntity disLike(@PathVariable("id") String id) {
        smallVideosService.disLike(id);
        return ResponseEntity.ok(null);
    }

    //评论列表
    @GetMapping("/{id}/comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   @PathVariable("id") String id) {
        PageResult pageResult = smallVideosService.comments(page, pagesize, id);
        return ResponseEntity.ok(pageResult);

    }

    //发布评论
    @PostMapping("/{id}/comments")
    public ResponseEntity saveComments(@RequestBody Map map, @PathVariable("id") String id) {
        String content = (String) map.get("comment");

        return ResponseEntity.ok(smallVideosService.saveComments(content, id));

    }


    //评论点赞
    /*/smallVideos/comments/:id/like*/
    @PostMapping("/comments/{id}/like")
    public ResponseEntity commentlike(@PathVariable("id") String id)
    {
        Integer like = commentsService.like(id);
        return ResponseEntity.ok(like);



    }//取消点赞
    /*/smallVideos/comments/:id/dislike*/
    @PostMapping("comments/{id}/dislike")
    public ResponseEntity commentdislike(@PathVariable("id") String id){
        Integer dislike = commentsService.dislike(id);
        return ResponseEntity.ok(dislike);
    }

}
